﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DASwindles;
using System.Collections;
using System.Xml;
using System.IO;
using OBSwindles;

namespace BLSwindles
{
    public static class BLFactory
    {
        #region BLCustomer
        public static IList<Customer> getCustomerDetails()
        {
            IBLClass blCustomer = new BLCustomer();
            IList customers = blCustomer.getDetails();
            IList<Customer> customerList = new List<Customer>();
            foreach (Customer value in customers)
                customerList.Add(value);

            return customerList;
        }

        public static Customer getCustomer_ByID(int pCustomerID)
        {
            IBLClass blCustomer = new BLCustomer();
            object objCustomer = blCustomer.getDetails_ByID(pCustomerID);
            return (Customer)objCustomer;
        }

        public static Customer getCustomer_ByCustomerNo(string pCustomerNo)
        {
            IList<Customer> customerList = getCustomerDetails();
            foreach (Customer customer in customerList)
            {
                if (customer.CustomerNo == pCustomerNo)
                {
                    return customer;
                }
            }
            return null;
        }

        public static Customer getCustomer_ByLoginUser(string pUserName)
        {
            Login login = getLoginCredentials(pUserName);
            if (login != null)
            {
                IList<Customer> customerList = getCustomerDetails();
                foreach (Customer customer in customerList)
                {
                    if (customer.LoginID == login.LoginID)
                    {
                        return customer;
                    }
                }
            }
            return null;
        }

        public static void updateCustomer(Customer p_Customer)
        {
            IBLClass blCustomer = new BLCustomer();
            blCustomer.updateDetails((object)p_Customer);
        }

        public static int insertCustomer(Customer p_Customer)
        {
            IBLClass blCustomer = new BLCustomer();
            int customerID = blCustomer.insertDetails((object)p_Customer);
            return customerID;
        }

        #endregion

        #region BLLogin
        public static Login getLoginCredentials(string p_UserName)
        {
            IBLClass blLogin = new BLLogin();
            IList loginDetails = blLogin.getDetails();

            foreach (Login obj in loginDetails)
            {
                if (string.Compare(obj.UserName, p_UserName, true) == 0)
                {
                       return obj;
                }
            }

            return null;
        }

        public static Login getLoginCredentials(string p_UserName, string p_Password)
        {
            Login login = getLoginCredentials(p_UserName);
            if (login != null)
            {
                if (string.Compare(login.Password, p_Password, true) == 0)
                {
                    return login;
                }
            }
            return null;

        }

        #endregion

        #region BLLoan

        public static LoanInfo getLoan_ByID(int pLoanID)
        {
            IBLClass blLoan = new BLLoan();
            object objLoanInfo = blLoan.getDetails_ByID(pLoanID);
            return (LoanInfo)objLoanInfo;
        }

        public static void updateLoan(LoanInfo p_Loan)
        {
            IBLClass blLoan = new BLLoan();
            blLoan.updateDetails((object)p_Loan);
        }
        #endregion

    }
}
